package ch.bfh.abch.rems;

import ch.bfh.abch.rems.interfaces.MulticasterDataPersister;
import ch.bfh.abch.rems.receiver.tinkerforge.TFMulticastReceiver;
import ch.bfh.abch.rems.sender.tinkerforge.TFMulticastSender;

public class REMSMulticastController {
    
    public static final int DEFAULT_BYTE_ARRAY_LENGTH = 256;
    private static final int DEFAULT_PORT = 9002;
    private static final String DEFAULT_MULTICAST_ADRESS = "233.233.233.233";

    private TFMulticastSender multicastSender;
    private TFMulticastReceiver multicastReceiver;
    private int port;
    private String multicastAdress;
    
    public REMSMulticastController(){
        this(DEFAULT_MULTICAST_ADRESS, DEFAULT_PORT);
    }
    
    public REMSMulticastController(String multicastAdress, int port){
        this.multicastAdress = multicastAdress;
        this.port = port;
    }
    
    public TFMulticastSender getMulticastSender(){
        if (this.multicastSender == null) {
            multicastSender = new TFMulticastSender(multicastAdress, port);
        }
        return multicastSender;
    }
    
    public void startMulticastReceiver(MulticasterDataPersister persiser){
        if (this.multicastReceiver == null) {
            multicastReceiver = new TFMulticastReceiver(persiser, multicastAdress, port);
        }
        multicastReceiver.startReceiving();
    }
    
    
}
